var fs = require('fs');
module.exports = {
    //异步方法
    writefileFunc:function (path, data,recall) {
        fs.writeFile(path,data,(err)=>{
            if(err)
            {
                throw err;
            }
            console.log('File saved');
            recall('写入文件成功');
        })
    },
    readfileFunc:(path,recall)=>{
        fs.readFile(path,(err,data)=>{
            if(err){
                console.log(err);
            }else{
                console.log(data.toString());
                recall(data);
            }
        });
    },
    readImg:function(path,res){
        fs.readFile(path,'binary',function(err,filedata){
            if(err){
                console.log(err);
                return;
            }else{
                console.log("输出文件"+path);
                res.write(filedata,'binary');
                res.end();
            }
        })
    }
}
